<template>
  <div class="tabbar-item" @click="itemClick">
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <div :class="{ active: isActive }">
      <slot name="item-text"></slot>
    </div>
    <!--  <img src="../../assets/images/tabbar/home.svg" alt="home小icon" />
   每一个图片下方都会多添加3px像素单位 
    <div>首页</div> 
    -->
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    path: String,
  },
  data() {
    return {
      isActive: true,
    };
  },
  methods: {
    itemClick() {
      this.$router.push(this.path); //点击则对页面进行路由跳转
    },
  },
};
</script>

<style>
/* 为每一个item添加flex属性 */
.tabbar-item {
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}
.tabbar-item img {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  margin-top: 3px;
}
.active {
  color: red;
}
</style>